package com.springboot.redis.dao;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

@Repository
public class RedisDao {
	private StringRedisTemplate template;

	@Autowired
	public void setTemplate(StringRedisTemplate template) {
		this.template = template;
	}

	public void setKey(String key, String value) {
		ValueOperations<String, String> ops = template.opsForValue();
		ops.set(key, value, 1, TimeUnit.MINUTES);// 1分钟过期
	}

	public String getValue(String key) {
		ValueOperations<String, String> ops = this.template.opsForValue();
		return ops.get(key);
	}

}
